package com.lkei.controller;

import com.alibaba.fastjson.JSONObject;
import com.lkei.dto.Result;
import com.lkei.entity.TheClass;
import com.lkei.service.TheClassService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("theClass")
public class TheClassController {

    @Autowired
    private TheClassService theClassService;

    @CrossOrigin
    @RequestMapping("findClasses")
    public Result findClasses(@RequestBody String data){
        // 将接收到的Json解析为map
        JSONObject jsonObject = JSONObject.parseObject(data);
        Map<String, Object> map = new HashMap<>();
        map.putAll(jsonObject);
        int teacher_id = Integer.valueOf(map.get("account").toString()).intValue();
        List<TheClass> classes = theClassService.findClasses(teacher_id);
        return Result.SUCCESS.setNewData(classes);
    }
}
